import Vue from 'vue'
import Vuex from 'vuex'
import { setStorage, getStorage } from '@/storage'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    refresh_token: getStorage('refresh_token'),
    token: getStorage('token'),
    user: JSON.parse(getStorage('user')) || {}// 用户基本信息
  },
  mutations: {
    setrefreshToken (state, refresh_token) {
      state.refresh_token = refresh_token
      setStorage('refresh_token', refresh_token)
    },
    setToken (state, token) {
      state.token = token
      setStorage('token', token)
    },
    clearToken (state) {
      state.token = ''
    },
    clearrefresh_token (state) {
      state.refresh_token = ''
    },
    setUser (state, n) {
      state.user = n
      setStorage('user', JSON.stringify(n))
    }
  },
  actions: {
  },
  modules: {
  }
})
